ifconfig 命令详解 | 您所在的位置:网站首页 › linux ifconfig 命令 › ifconfig 命令详解 |
1 概述
ifconfig工具不仅可以被用来简单地获取网络接口配置信息,还可以修改这些配置。用ifconfig命令配置的网卡信息,在网卡重启后机器重启后,配置就不存在。要想将上述的配置信息永远的存的电脑里,那就要修改网卡的配置文件了。 2 命令详解 2.1 命令常见参数 Usage: ifconfig [-a] [-v] [-s] [[] ] [add [/]] [del [/]] [[-]broadcast []] [[-]pointopoint []] [netmask ] [dstaddr ] [tunnel ] [outfill ] [keepalive ] [hw ] [metric ] [mtu ] [[-]trailers] [[-]arp] [[-]allmulti] [multicast] [[-]promisc] [mem_start ] [io_addr ] [irq ] [media ] [txqueuelen ] [[-]dynamic] [up|down] ... 复制代码 2.2 命令常见参数说明(1) 显示激活的网卡信息 ifconfig 复制代码(2) 显示所有的网卡信息 ifconfig -a 复制代码(3) 显示简要的网卡信息 ifconfig -s 复制代码 3.2 启动关闭指定网卡(1) 关闭网卡 ifconfig eth0 down 复制代码(2) 启动网卡 ifconfig eth0 up 复制代码 3.3 配置和删除ip地址(1) 配置ip // 配置ip地址 ifconfig eth0 192.168.1.100 // 配置ip地址和子网掩码 ifconfig eth0 192.168.1.100 netmask 255.255.255.0 // 配置ip地址、子网掩码和广播地址 ifconfig eth0 192.168.1.100 netmask 255.255.255.0 broadcast 192.168.1.255 复制代码(2) 单网卡添加多个IP地址 ifconfig eth0:0 192.168.1.100 netmask 255.255.255.0 up ifconfig eth0:1 192.168.2.100 netmask 255.255.255.0 up 复制代码(3) 删除IP地址 ifconfig eth0 del 192.168.1.100 复制代码 3.4 修改MAC地址 ifconfig eth0 hw ether 00:AA:BB:CC:DD:EE 复制代码 3.5 启用和关闭ARP协议(1) 启用arp ifconfig eth0 arp 复制代码(2) 禁用arp ifconfig eth0 -arp 复制代码禁用arp的时候,可以看到出现NOARP字段。 [root@localhost ~]# ifconfig eth0 arp [root@localhost ~]# [root@localhost ~]# ifconfig eth0 eth0: flags=4163 mtu 1500 inet 192.168.1.135 netmask 255.255.255.0 broadcast 192.168.1.255 inet6 fe80::20c:29ff:fe9b:52d3 prefixlen 64 scopeid 0x20 ether 00:aa:bb:cc:dd:ee txqueuelen 1000 (Ethernet) RX packets 2635 bytes 204710 (199.9 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1071 bytes 144688 (141.2 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@localhost ~]# ifconfig eth0 -arp [root@localhost ~]# [root@localhost ~]# ifconfig eth0 eth0: flags=4291 mtu 1500 inet 192.168.1.135 netmask 255.255.255.0 broadcast 192.168.1.255 inet6 fe80::20c:29ff:fe9b:52d3 prefixlen 64 scopeid 0x20 ether 00:aa:bb:cc:dd:ee txqueuelen 1000 (Ethernet) RX packets 2636 bytes 204770 (199.9 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1071 bytes 144688 (141.2 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 复制代码 3.6 设置最大传输单元 ifconfig eth0 mtu 1500 复制代码 3.7 设置网卡的promiscuous模式(1) 启用 ifconfig eth0 promisc 复制代码(2) 禁用 ifconfig eth0 -promisc 复制代码如果选择此参数,网卡将接收网络中发给它所有的数据包。当启用时出现PROMISC字段。 [root@localhost ~]# ifconfig eth0 promisc [root@localhost ~]# [root@localhost ~]# [root@localhost ~]# ifconfig eth0 eth0: flags=4419 mtu 1500 inet 192.168.1.135 netmask 255.255.255.0 broadcast 192.168.1.255 inet6 fe80::20c:29ff:fe9b:52d3 prefixlen 64 scopeid 0x20 ether 00:aa:bb:cc:dd:ee txqueuelen 1000 (Ethernet) RX packets 2659 bytes 206696 (201.8 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1071 bytes 144688 (141.2 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@localhost ~]# [root@localhost ~]# ifconfig eth0 -promisc [root@localhost ~]# [root@localhost ~]# [root@localhost ~]# ifconfig eth0 eth0: flags=4163 mtu 1500 inet 192.168.1.135 netmask 255.255.255.0 broadcast 192.168.1.255 inet6 fe80::20c:29ff:fe9b:52d3 prefixlen 64 scopeid 0x20 ether 00:aa:bb:cc:dd:ee txqueuelen 1000 (Ethernet) RX packets 2661 bytes 206816 (201.9 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1071 bytes 144688 (141.2 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 复制代码 3.8 设置网卡的多播模式(1) 启用 ifconfig eth0 allmulti 复制代码(2) 禁用 ifconfig eth0 -allmulti 复制代码如果选择此参数,网卡将接收网络中所有的多播数据包。当启用时会出现MULTICAST字段。 [root@localhost ~]# ifconfig eth0 allmulti [root@localhost ~]# [root@localhost ~]# ifconfig eth0 eth0: flags=4675 mtu 1500 inet 192.168.1.135 netmask 255.255.255.0 broadcast 192.168.1.255 inet6 fe80::20c:29ff:fe9b:52d3 prefixlen 64 scopeid 0x20 ether 00:aa:bb:cc:dd:ee txqueuelen 1000 (Ethernet) RX packets 2676 bytes 207716 (202.8 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1071 bytes 144688 (141.2 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@localhost ~]# [root@localhost ~]# ifconfig eth0 -allmulti [root@localhost ~]# [root@localhost ~]# [root@localhost ~]# ifconfig eth0 eth0: flags=4163 mtu 1500 inet 192.168.1.135 netmask 255.255.255.0 broadcast 192.168.1.255 inet6 fe80::20c:29ff:fe9b:52d3 prefixlen 64 scopeid 0x20 ether 00:aa:bb:cc:dd:ee txqueuelen 1000 (Ethernet) RX packets 2676 bytes 207716 (202.8 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1071 bytes 144688 (141.2 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 复制代码 3.9 配置和删除IPv6地址(1) 添加 ifconfig eth0 add 3ffe:3240:800:1005::2/64 复制代码(2) 删除 ifconfig eth0 del 3ffe:3240:800:1005::2/64 复制代码 |
CopyRight 2018-2019 实验室设备网 版权所有 |